package com.yfp.operation.controller;

import com.yfp.common.core.domain.R;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.common.core.web.page.TableDataInfo;
import com.yfp.operation.domain.MallProduct;
import com.yfp.operation.service.MallProductService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 商城商品
 * 
 * @CreateDate: 2025/2/24 15:23
 * @UpdateUser: 
 * @UpdateDate: 2025/2/24 15:23
 * @UpdateRemark: 暂无修改
 * @Version: 1.0
 */
@RestController
@RequestMapping("/mallProduct")
@Tag(name = "商城商品管理")
public class MallProductController extends BaseController {

    @Autowired
    private MallProductService mallProductService;

    @GetMapping("/list")
    @Operation(summary = "商品列表")
    public R<TableDataInfo> getList(MallProduct mallProduct) {
        startPage();
        return R.ok(getDataTable(mallProductService.getList(mallProduct)));
    }
    @GetMapping("/{id}")
    @Operation(summary = "详情")
    R<MallProduct> info(@PathVariable Long id) {
        MallProduct mallProduct = mallProductService.findInfoById(id);
        return R.ok(mallProduct);
    }
    @PostMapping("")
    @Operation(summary = "新增")
    public R<Void> add(@RequestBody MallProduct mallProduct) {
        mallProductService.add(mallProduct);
        return R.ok();
    }
    @PutMapping("")
    @Operation(summary = "编辑")
    public R<Void> edit(@RequestBody MallProduct mallProduct) {
        mallProductService.edit(mallProduct);
        return R.ok();
    }

    @PutMapping("/editStatus")
    @Operation(summary = "上架/下架")
    public R<Void> editStatus(@RequestBody MallProduct mallProduct) {
        MallProduct mallProduct1 = mallProductService.findInfoById(mallProduct.getId());
        mallProduct1.setStatus(mallProduct.getStatus());
        mallProductService.edit(mallProduct1);
        return R.ok();
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除")
    R<Void> del(@PathVariable Long id) {
        MallProduct mallProduct = mallProductService.findInfoById(id);
        mallProduct.setStatus(0);
        mallProductService.edit(mallProduct);
        return R.ok();
    }
}
